﻿using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections;
using Trying1.Properties;
using Trying1.Classes;
using System.Data.SqlClient;
using System.Data;

namespace Trying1
{
    /// <summary>
    /// Interaction logic for ReceptionForm.xaml
    /// </summary>
    /// 
     
    public partial class ReceptionForm : Window
    {
        public ReceptionForm()
        {
            InitializeComponent();
            ArrayList room = new ArrayList();
            room = RoomDBManager.GetAll();
            foreach (Room r in room)
            {
                cBoxSelectRoom.Items.Add(Convert.ToString(r.roomNum));
            }
           
            foreach (Room r in room)
            {
                cBoxGuestRoom.Items.Add(Convert.ToString(r.roomNum));
            }
            foreach (Room r in room)
            {
                cBoxPaymentRoom.Items.Add(Convert.ToString(r.roomNum));
            }
           
        }	
        
		private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
    		DragMove();
		}
		private void btnCloseR_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// TODO: Add event handler implementation here.
            Login objLogin = new Login();
			this.Close();
			objLogin.Show();
			
		}
		private void btnMinR_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// TODO: Add event handler implementation here.
			SystemCommands.MinimizeWindow(this);
		}
        //HomePage
        private void btnRetrieve_Click(object sender, RoutedEventArgs e)
        {
            DateTime checkIndate = Convert.ToDateTime(dtpCheckIn.Text);
            DateTime checkOutdate = Convert.ToDateTime(dtpCheckOut.Text);

            ArrayList ar = new ArrayList();
            //check if a roomType is selected, if not customer is ok with any room

            if (cbRoomType.SelectedItem == null)
            {
                //retrieve any room that is vacant
                ar = RoomDBManager.GetAll1();
            }

            else if (cbRoomType.SelectedIndex == 0)
            {
                //retrieve any room that is vacant
                ar = RoomDBManager.GetAll1();
            }
            else
            {
                ComboBoxItem selectedItem = (ComboBoxItem)(cbRoomType.SelectedValue);
                string roomType = (string)(selectedItem.Content);
                //retrieve room that is vacant, and the selected roomType
                ar = RoomDBManager.GetRoomByRoomType(roomType);
            }
            ArrayList bookedrooms = new ArrayList();
            bookedrooms = BookingDBManager.GetRoomByDate(checkIndate, checkOutdate);
            //bookedrooms returning null,means all rooms are available for booking
            if (bookedrooms.Count == 0)
            {
                dghome.ItemsSource = ar;

            }
            //booked rooms not returning null, means that certain rooms are not available for booking
            else
            {
                ArrayList finalrooms = new ArrayList();
                foreach (Room r in ar)
                {
                    foreach (Booking b in bookedrooms)
                    {


                        if (r.roomNum.Equals(b.roomNum))
                        {
                            finalrooms.Add(r.roomNum);
                        }
                    }
                }

                dghome.ItemsSource = ar;

            }
            LoginInfo.checkInDate = checkIndate;
            LoginInfo.checkOutDate = checkOutdate;
        }
        private void btnBookHome_Click(object sender, RoutedEventArgs e)	
         {
            ArrayList list = dghome.ItemsSource as ArrayList;
            foreach (var row in list)	
            {
                bool IsChecked = (bool)((CheckBox)dghome.Columns[0].GetCellContent(row)).IsChecked;	
                if (IsChecked)	
               {	
	                    string roomNo = (dghome.Columns[1].GetCellContent(row) as TextBlock).Text;
	                    lblRoomNum.Content = roomNo;	
                    this.tabReservation.IsSelected = true;	
           }	
	
          }	

        }
        //Reservation Tab
        private void btnSubmitReserve_Clic(object sender, RoutedEventArgs e)
        {
            if (tbxFirstNameR.Text == null || tbxLastNameR.Text == null || tbxGuestR.Text == null || tbxChildrenR.Text == null || tbxEmailR.Text == null || tbxAddressR.Text == null || tbxPhoneR.Text == null || tbxHouseNoR1.Text == null || tbxPostCodeR.Text == null || tbxCountry.Text == null || cbPaymentR.Text == null || tbxccNoR1.Text == null || tbxccNoR2.Text == null || tbxccNoR3.Text == null || tbxccNoR4.Text == null || tbxccName.Text == null || cexpDateR.SelectedDate == null)
            {
                MessageBox.Show("Please fill in all the fields!",
       "Important Note", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                Guest g = new Guest();
                g.firstName = tbxFirstNameR.Text;
                g.lastName = tbxLastNameR.Text;
                g.noOfGuest = Convert.ToInt32(tbxGuestR.Text);
                g.noOfChildren = Convert.ToInt32(tbxChildrenR.Text);
                g.emailAddress = tbxEmailR.Text;
                g.streetAddress = tbxAddressR.Text;
                g.phoneNum = Convert.ToInt64(tbxPhoneR.Text);
                g.houseNo = tbxHouseNoR1.Text;
                g.postalCode = tbxPostCodeR.Text;
                g.country = tbxCountry.Text;
                ComboBoxItem selectedItem = (ComboBoxItem)(cbPaymentR.SelectedValue);
                g.paymentType = (string)(selectedItem.Content);
                g.ccNo = tbxccNoR1.Text + "-" + tbxccNoR2.Text + "-" + tbxccNoR3.Text + "-" + tbxccNoR4.Text;
                g.ccName = tbxccName.Text;
                g.expDate = (DateTime)cexpDateR.SelectedDate;
                g.roomNum = Convert.ToInt32(lblRoomNum.Content);
                if (GuestDBManager.InsertGuest(g) > 0)
                {
                    Guest m = GuestDBManager.GetInsertedGuestReservation(g.firstName, g.lastName, g.roomNum);
                    Booking b = new Booking();
                    b.roomNum = g.roomNum;
                    b.guestNo = m.guestNo;
                    b.checkInDate = LoginInfo.checkInDate;
                    b.checkOutDate = LoginInfo.checkOutDate;
                    if (tbxaddReq.Text == "<-Please Enter->")
                    {
                        b.addReq = "None";
                    }
                    else
                    {
                        b.addReq = tbxaddReq.Text;
                    }
                    BookingDBManager.InsertBookingbyGuest(b);
                    MessageBox.Show("Guest has been added!");
                    this.tabHome.IsSelected = true;
                    ClearReservationBox();
                }

            }
            
        }
        //Check In Tab
        ArrayList guest = new ArrayList();
        private void btnSearchCheckIn_Click(object sender, RoutedEventArgs e)
        {
            //if all empty
           if(tbxBookingIdCI.Text=="" && tbxLastName.Text=="" && dpcheckinCI.SelectedDate==null && dpcheckoutCI.SelectedDate==null)
           {
               MessageBox.Show("Please fill in one or all the fields!",
       "Important Note", MessageBoxButton.OK, MessageBoxImage.Exclamation);
           }
           //if lastname is entered
           else if(tbxLastName.Text!="" && tbxBookingIdCI.Text=="" && dpcheckinCI.SelectedDate==null && dpcheckoutCI.SelectedDate==null)
           {

               guest = GuestBookingDBManager.GetGuestBylastName(tbxLastName.Text);
               if (guest.Count > 1)
               {
                   gbgD.Visibility = Visibility.Hidden;
                   gbFindAll.Visibility = Visibility.Visible;
                   gbCheckInGuest.Visibility = Visibility.Hidden;
                   dgCheckIn.ItemsSource = guest;
               }
               else if(guest.Count==1)
               {
                   gbgD.Visibility = Visibility.Hidden;
                   gbFindAll.Visibility = Visibility.Hidden;
                   gbCheckInGuest.Visibility = Visibility.Visible;
                   foreach (GuestBooking i in guest)
                   {
                       lblguestidtext.Content = Convert.ToString(i.guestNo);
                       lbllastnametext.Content = i.lastName;
                       lblfirstnametext.Content = i.firstName;
                       lblroomnumtext.Content = i.roomNum;
                       lblroomrateCI.Content = i.roomRates;
                       ccidCI.SelectedDate = i.checkInDate.Date;
                       ccodCI.SelectedDate = i.checkOutDate.Date;
                       tbxaddReqCI.Text = i.addReq;
                       clearCheckIn();
                   }
                   

               }
               else
               {
                       MessageBox.Show("There is no such entry, Please Try Again!",
                    "Important Note", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                   
               }

           }
            //if guestNo is entered
           else if(tbxBookingIdCI.Text!="" && tbxLastName.Text=="" && dpcheckinCI.SelectedDate==null && dpcheckoutCI.SelectedDate==null)
           {
               GuestBooking g = GuestBookingDBManager.GetCheckInByguestNo(Convert.ToInt32(tbxBookingIdCI.Text));
               if(g==null)
               {
                   MessageBox.Show("There is no such entry, Please Try Again!",
                "Important Note", MessageBoxButton.OK, MessageBoxImage.Exclamation);
               }
               else
               {
                   gbgD.Visibility = Visibility.Hidden;
                   gbFindAll.Visibility = Visibility.Hidden;
                   gbCheckInGuest.Visibility = Visibility.Visible;
                   lblguestidtext.Content = Convert.ToString(g.guestNo);
                   lbllastnametext.Content = g.lastName;
                   lblfirstnametext.Content = g.firstName;
                   lblroomnumtext.Content = g.roomNum;
                   lblroomrateCI.Content = g.roomRates;
                   ccidCI.SelectedDate = g.checkInDate;
                   ccodCI.SelectedDate = g.checkOutDate;
                   tbxaddReqCI.Text = g.addReq;
                   clearCheckIn();
               }
               
           }
            //if guestNo and lastName is entered
           else if(tbxBookingIdCI.Text!="" && tbxLastName.Text!="" && dpcheckinCI.SelectedDate==null && dpcheckoutCI.SelectedDate==null)
            {
                
                GuestBooking g = GuestBookingDBManager.GetGuestBylastnameguestno(Convert.ToInt32(tbxBookingIdCI.Text), tbxLastName.Text);
               if(g==null)
               {
                   MessageBox.Show("There is no such entry, Please Try Again!",
                     "Important Note", MessageBoxButton.OK, MessageBoxImage.Exclamation);
               }
               gbgD.Visibility = Visibility.Hidden;
                gbFindAll.Visibility = Visibility.Hidden;
                gbCheckInGuest.Visibility = Visibility.Visible;
                lblguestidtext.Content = Convert.ToString(g.guestNo);
                lbllastnametext.Content = g.lastName;
                lblfirstnametext.Content = g.firstName;
                lblroomnumtext.Content = g.roomNum;
                lblroomrateCI.Content = g.roomRates;
                ccidCI.SelectedDate = g.checkInDate;
                ccodCI.SelectedDate = g.checkOutDate;
                tbxaddReqCI.Text = g.addReq;
               clearCheckIn();
               
            }
            //if lastName and checkInDate is entered
            else if(tbxLastName.Text!="" && dpcheckinCI.SelectedDate!=null && tbxBookingIdCI.Text=="" && dpcheckoutCI.SelectedDate==null)
            {

                guest = GuestBookingDBManager.GetCheckInlastNameCIDate(tbxLastName.Text, Convert.ToDateTime(dpcheckinCI.SelectedDate));
                if (guest.Count > 1)
                {
                    gbgD.Visibility = Visibility.Hidden;
                    gbFindAll.Visibility = Visibility.Visible;
                    gbCheckInGuest.Visibility = Visibility.Hidden;
                    dgCheckIn.ItemsSource = guest;
                }
                else if(guest.Count==1)
                {
                    gbgD.Visibility = Visibility.Hidden;
                    gbFindAll.Visibility = Visibility.Hidden;
                    gbCheckInGuest.Visibility = Visibility.Visible;
                    foreach (GuestBooking i in guest)
                    {
                        lblguestidtext.Content = Convert.ToString(i.guestNo);
                        lbllastnametext.Content = i.lastName;
                        lblfirstnametext.Content = i.firstName;
                        lblroomnumtext.Content = i.roomNum;
                        lblroomrateCI.Content = i.roomRates;
                        ccidCI.SelectedDate = i.checkInDate;
                        ccodCI.SelectedDate = i.checkOutDate;
                        tbxaddReqCI.Text = i.addReq;
                        clearCheckIn();
                    }
                    

                }
                else
                {
                   MessageBox.Show("There is no such entry, Please Try Again!",
                    "Important Note", MessageBoxButton.OK, MessageBoxImage.Exclamation);
               
                }
            }
               //lastname, checkin and checkout is entered
           else if (tbxLastName.Text != "" && dpcheckinCI.SelectedDate != null && tbxBookingIdCI.Text == "" && dpcheckoutCI.SelectedDate != null)
           {
               guest = GuestBookingDBManager.GetCheckInBylastnamecico(tbxLastName.Text, Convert.ToDateTime(dpcheckinCI.SelectedDate), Convert.ToDateTime(dpcheckoutCI.SelectedDate));
               if (guest.Count > 1)
               {
                   gbgD.Visibility = Visibility.Hidden;
                   gbFindAll.Visibility = Visibility.Visible;
                   gbCheckInGuest.Visibility = Visibility.Hidden;
                   dgCheckIn.ItemsSource = guest;
               }
               else if(guest.Count==1)
               {
                   gbgD.Visibility = Visibility.Hidden;
                   gbFindAll.Visibility = Visibility.Hidden;
                   gbCheckInGuest.Visibility = Visibility.Visible;
                   foreach (GuestBooking i in guest)
                   {
                       lblguestidtext.Content = Convert.ToString(i.guestNo);
                       lbllastnametext.Content = i.lastName;
                       lblfirstnametext.Content = i.firstName;
                       lblroomnumtext.Content = i.roomNum;
                       lblroomrateCI.Content = i.roomRates;
                       ccidCI.SelectedDate = i.checkInDate;
                       ccodCI.SelectedDate = i.checkOutDate;
                       tbxaddReqCI.Text = i.addReq;
                       clearCheckIn();
                   }


               }
               else
               {
                   MessageBox.Show("There is no such entry, Please Try Again!",
                    "Important Note", MessageBoxButton.OK, MessageBoxImage.Exclamation);
               
               }
           }
           else
           {
               MessageBox.Show("Please enter one more field!",
       "Important Note", MessageBoxButton.OK, MessageBoxImage.Exclamation);
           }
            
        }
         private void ClearReservationBox()
          {
              tbxFirstNameR.Text = "";
              tbxLastNameR.Text = "";
              tbxGuestR.Text = "";
              tbxChildrenR.Text = "";
              tbxEmailR.Text = "";
              tbxAddressR.Text = "";
              tbxPhoneR.Text = "";
              tbxHouseNoR1.Text = "";
              tbxPostCodeR.Text = "";
              tbxCountry.Text = "";
              cbPaymentR.SelectedIndex=0;
              tbxccNoR1.Text = ""; tbxccNoR2.Text = ""; tbxccNoR3.Text = ""; tbxccNoR4.Text = "";
              tbxccName.Text = "";
              cexpDateR.SelectedDate=null;
              tbxaddReq.Text = "";
              lblRoomNum.Content = "";
              
          }

         private void btnRetrieveAll_Click(object sender, RoutedEventArgs e)
         {
             gbFindAll.Visibility = Visibility.Visible;
             gbgD.Visibility = Visibility.Hidden;
             gbCheckInGuest.Visibility = Visibility.Hidden;
             clearCheckIn();
             ArrayList guestlist = new ArrayList();
             guestlist = GuestDBManager.FindAllGuest();
            
             dgCheckIn.ItemsSource = guestlist;
             
        }
         private void clearCheckIn()
         {
             tbxBookingIdCI.Text = "";
             tbxLastName.Text = "";
             dtpCheckIn.SelectedDate = null;
             dtpCheckIn.Text = null;
             dtpCheckOut.SelectedDate = null;
             dtpCheckOut.Text = null;
         }
         private void btnSelectCI_Click(object sender, RoutedEventArgs e)
         {
             ArrayList list = dgCheckIn.ItemsSource as ArrayList;

             foreach (var row in list)
             {
                 bool IsChecked = (bool)((CheckBox)dgCheckIn.Columns[0].GetCellContent(row)).IsChecked;

                 if (IsChecked)
                 {
                     string guestNo = (dgCheckIn.Columns[1].GetCellContent(row) as TextBlock).Text;
                     GuestBooking g = GuestBookingDBManager.GetCheckInByguestNo(Convert.ToInt32(guestNo));
                     gbFindAll.Visibility = Visibility.Hidden;
                     gbCheckInGuest.Visibility = Visibility.Visible;
                     gbgD.Visibility = Visibility.Hidden;

                     lblguestidtext.Content = g.guestNo;
                     lbllastnametext.Content = g.lastName;
                     lblfirstnametext.Content = g.firstName;
                     lblroomnumtext.Content = g.roomNum;
                     lblroomrateCI.Content = g.roomRates;
                     ccidCI.SelectedDate = g.checkInDate;
                     ccodCI.SelectedDate = g.checkOutDate;
                     tbxaddReqCI.Text = g.addReq;
                     clearCheckIn();
                 }

             }
         }
         private void btnCheckInCI_Click(object sender, RoutedEventArgs e)
         {
             RoomDBManager.UpdateGuestCheckIn(Convert.ToInt32(lblroomnumtext.Content),tbxaddReqCI.Text,Convert.ToDateTime(ccodCI.SelectedDate),Convert.ToInt32(lblguestidtext.Content));
             MessageBox.Show("Guest Checked In!",
       "Checked In", MessageBoxButton.OK,MessageBoxImage.None);
             clearCheckIn();
             gbgD.Visibility = Visibility.Hidden;
             gbCheckInGuest.Visibility = Visibility.Hidden;
             gbFindAll.Visibility = Visibility.Visible;
             this.tabHome.IsSelected = true;
         }
         private void btnUpdateCI_Click(object sender, RoutedEventArgs e)
         {
             gbCheckInGuest.Visibility = Visibility.Hidden;
             gbFindAll.Visibility = Visibility.Hidden;
             gbgD.Visibility = Visibility.Visible;
             Guest g = GuestDBManager.GetGuestByguestNo(Convert.ToInt32(lblguestidtext.Content));
             lblgdguestno.Content = g.guestNo;
             lblgdroomNum.Content = g.roomNum;
             tbxgdfirstName.Text = g.firstName;
             tbxgdlastName.Text = g.lastName;
             cbgdnoGuest.SelectedIndex = g.noOfGuest-1;
             cbgdnoChildren.SelectedIndex = g.noOfChildren;
             tbxgdphoneNum.Text = Convert.ToString(g.phoneNum);
             tbxgdemailAdd.Text = g.emailAddress;
             tbxgdstreetAdd.Text = g.streetAddress;
             tbxgdhouseNo.Text = g.houseNo;
             tbxgdpostalCode.Text = g.postalCode;
             tbxgdCountry.Text = g.country;
             if (g.paymentType == "Cash")
             {
                 cbgdpaymentType.SelectedIndex=0;
             }
             else if (g.paymentType == "Credit Card")
             {
                 cbgdpaymentType.SelectedIndex=1;
             }
             tbxgdcreditCardName.Text = g.ccName;
             dtpgdexpDate.SelectedDate = g.expDate;
             tbxgdccNo.Text = g.ccNo;
         }
         private void btngdDelete_Click(object sender, RoutedEventArgs e)
         {
             MessageBoxResult result =  MessageBox.Show("Are you sure you want to delete "+lblgdguestno.Content+", "+tbxgdfirstName.Text+"?","Delete Confimation",MessageBoxButton.YesNo);
             if (result == MessageBoxResult.Yes)
             {
                 GuestDBManager.DeleteGuest(Convert.ToInt32(lblgdguestno.Content));
                 BookingDBManager.DeleteGuestBooking(Convert.ToInt32(lblgdguestno.Content));
                 MessageBox.Show("Guest deleted!");
                 gbgD.Visibility = Visibility.Hidden;
                 gbCheckInGuest.Visibility = Visibility.Hidden;
                 clearCheckIn();
                 ArrayList guestlist = new ArrayList();
                 guestlist = GuestDBManager.FindAllGuest();
                 dgCheckIn.ItemsSource = guestlist;
                 gbFindAll.Visibility = Visibility.Visible;
             }
         }

         private void btngdUpdate_Click(object sender, RoutedEventArgs e)
         {

             gbCheckInGuest.Visibility = Visibility.Visible;
             gbFindAll.Visibility = Visibility.Hidden;
             gbgD.Visibility = Visibility.Hidden;
             Guest g = new Guest();
             g.guestNo = Convert.ToInt32(lblgdguestno.Content);
             //lblgdguestno.Content = g.guestNo;
             g.roomNum = Convert.ToInt32(lblgdroomNum.Content);
             g.firstName = tbxgdfirstName.Text;
             g.lastName = tbxgdlastName.Text; 
             g.noOfGuest=cbgdnoGuest.SelectedIndex + 1;
             g.noOfChildren = cbgdnoChildren.SelectedIndex;
             g.phoneNum = Convert.ToInt64(tbxgdphoneNum.Text);
             g.emailAddress = tbxgdemailAdd.Text;
             g.streetAddress =tbxgdstreetAdd.Text ;
             g.houseNo = tbxgdhouseNo.Text;
             g.postalCode= tbxgdpostalCode.Text ;
             g.country = tbxgdCountry.Text ;
             ComboBoxItem selectedItem = (ComboBoxItem)(cbgdpaymentType.SelectedValue);
             g.paymentType = (string)(selectedItem.Content);
             g.ccName= tbxgdcreditCardName.Text;
             g.ccNo = tbxgdccNo.Text;
             g.expDate = Convert.ToDateTime(dtpgdexpDate.SelectedDate);
             GuestDBManager.UpdateGuest(g);
             MessageBox.Show("Guest: " + tbxgdfirstName.Text + " " + tbxgdlastName.Text + " has been updated!");
             GuestBooking m = GuestBookingDBManager.GetCheckInByguestNo(Convert.ToInt32(g.guestNo));
             lblguestidtext.Content = Convert.ToString(m.guestNo);
             lbllastnametext.Content = m.lastName;
             lblfirstnametext.Content = m.firstName;
             lblroomnumtext.Content = m.roomNum;
             lblroomrateCI.Content = m.roomRates;
             ccidCI.SelectedDate = m.checkInDate;
             ccodCI.SelectedDate = m.checkOutDate;
             tbxaddReqCI.Text = m.addReq;
            
         }

        //Report Tab For Receptionist
        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            lblRoomNumHighlight.Visibility = Visibility.Visible;
            lblRoomRateHighlight.Visibility = Visibility.Visible;
            lblRoomStatusHighlight.Visibility = Visibility.Visible;
            lblRoomTypeHighlight.Visibility = Visibility.Visible;
            lblRoomnum.Visibility = Visibility.Visible;
            lblRoomrate.Visibility = Visibility.Visible;
            lblRoomstatus.Visibility = Visibility.Visible;
            lblRoomtype.Visibility = Visibility.Visible;
            dGRooms.Visibility = Visibility.Hidden;
            string roomNum = cBoxSelectRoom.SelectedItem.ToString();
            //ComboBoxItem selectedItem = (ComboBoxItem)(cBoxSelectRoom.SelectedValue);
            //string roomNum = (string)(selectedItem.Content);
            int selectedVal = Convert.ToInt32(roomNum);
            Room r = ReportDBManager.GetRoomAndStatus(selectedVal);
            lblRoomnum.Content = r.roomNum;
            lblRoomrate.Content = r.roomRate;
            lblRoomstatus.Content = r.roomStatus;
            lblRoomtype.Content = r.roomType;
            
        }
        private void BtnGetAll_Click(object sender, RoutedEventArgs e)
        {
            lblRoomNumHighlight.Visibility = Visibility.Hidden;
            lblRoomRateHighlight.Visibility = Visibility.Hidden;
            lblRoomStatusHighlight.Visibility = Visibility.Hidden;
            lblRoomTypeHighlight.Visibility = Visibility.Hidden;
            lblRoomnum.Visibility = Visibility.Hidden;
            lblRoomrate.Visibility = Visibility.Hidden;
            lblRoomstatus.Visibility = Visibility.Hidden;
            lblRoomtype.Visibility = Visibility.Hidden;
            dGRooms.Visibility = Visibility.Visible;
            ArrayList room = new ArrayList();
            room = ReportDBManager.GetAllRoomsandStatus();
            dGRooms.ItemsSource = room;
        }
        private void cBoxGuestRoom_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
            lblHouseNum1.Visibility = Visibility.Visible;
            lblPhoneNum1.Visibility = Visibility.Visible;
            lblFirstName1.Visibility = Visibility.Visible;
            lblLastName1.Visibility = Visibility.Visible;
            lblNoOfGuests1.Visibility = Visibility.Visible;
            lblPostalCode1.Visibility = Visibility.Visible;
            lblStreetAddress1.Visibility = Visibility.Visible;
            lblEmailAddress1.Visibility = Visibility.Visible;
            lblCountry1.Visibility = Visibility.Visible;
            lblHouseNum2.Visibility = Visibility.Visible;
            lblPhoneNum2.Visibility = Visibility.Visible;
            lblFirstName2.Visibility = Visibility.Visible;
            lblLastName2.Visibility = Visibility.Visible;
            lblNoOfGuests2.Visibility = Visibility.Visible;
            lblPostalCode2.Visibility = Visibility.Visible;
            lblStreetAddress2.Visibility = Visibility.Visible;
            lblEmailAddress2.Visibility = Visibility.Visible;
            lblCountry2.Visibility = Visibility.Visible;
            dGGuests.Visibility = Visibility.Hidden;
            if (cBoxGuestRoom.SelectedItem != null)
            {
                string roomNum = cBoxGuestRoom.SelectedItem.ToString();
                //ComboBoxItem selectedItem = (ComboBoxItem)(cBoxSelectRoom.SelectedValue);
                //string roomNum = (string)(selectedItem.Content);
                int selectedVal = Convert.ToInt32(roomNum);
                Guest r = ReportDBManager.GetGuestByRoomNum(selectedVal);
                lblHouseNum1.Content = r.houseNo;
                lblPhoneNum1.Content = r.phoneNum;
                lblFirstName1.Content = r.firstName;
                lblLastName1.Content = r.lastName;
                lblNoOfGuests1.Content = Convert.ToString(r.noOfGuest);
                lblPostalCode1.Content = r.postalCode;
                lblStreetAddress1.Content = r.streetAddress;
                lblEmailAddress1.Content = r.emailAddress;
                lblCountry1.Content = r.country;
                dPickGuestDate.SelectedDate = null;
            }
            
            
            
        }
        private void dPickGuestDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            cBoxGuestRoom.SelectedValue = null;
            lblHouseNum1.Visibility = Visibility.Hidden;
            lblPhoneNum1.Visibility = Visibility.Hidden;
            lblFirstName1.Visibility = Visibility.Hidden;
            lblLastName1.Visibility = Visibility.Hidden;
            lblNoOfGuests1.Visibility = Visibility.Hidden;
            lblPostalCode1.Visibility = Visibility.Hidden;
            lblStreetAddress1.Visibility = Visibility.Hidden;
            lblEmailAddress1.Visibility = Visibility.Hidden;
            lblCountry1.Visibility = Visibility.Hidden;
            lblHouseNum2.Visibility = Visibility.Hidden;
            lblPhoneNum2.Visibility = Visibility.Hidden;
            lblFirstName2.Visibility = Visibility.Hidden;
            lblLastName2.Visibility = Visibility.Hidden;
            lblNoOfGuests2.Visibility = Visibility.Hidden;
            lblPostalCode2.Visibility = Visibility.Hidden;
            lblStreetAddress2.Visibility = Visibility.Hidden;
            lblEmailAddress2.Visibility = Visibility.Hidden;
            lblCountry2.Visibility = Visibility.Hidden;
            dGGuests.Visibility = Visibility.Visible;
            if (dPickGuestDate.SelectedDate != null)
            {
                DateTime selectedDate = Convert.ToDateTime(dPickGuestDate.Text);
                ArrayList guest = new ArrayList();
                guest = ReportDBManager.GetAllGuestsInAllRoomsOnASpecificDate(selectedDate);
                dGGuests.ItemsSource = guest;
            }
        }
        private void cBoxGuestRoom_DropDownOpened(object sender, EventArgs e)
        {
            dPickGuestDate.SelectedDate = null;
        }
        
        //Check-Out Tab For Receptionist
        private void cBoxPaymentRoom_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string roomNum = cBoxPaymentRoom.SelectedItem.ToString();
            
            {
                int selectedVal = Convert.ToInt32(roomNum);
                ArrayList booking = new ArrayList();
                booking = CheckoutDBManager.GetAllBookingByroomNum(selectedVal);
                dGBookingDetails.ItemsSource = booking;
                dGBookingDetails.Visibility = Visibility.Visible;
            }

        }
        private void cBoxGuestNo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int guestNo = Convert.ToInt32(cBoxGuestNo.SelectedItem);
            Guest g = CheckoutDBManager.GetCreditCardInfoByGuestNo(guestNo);
            Booking b = CheckoutDBManager.GetCheckInByGuestNo(guestNo);
            if (g.ccName != null && g.ccNo != null && g.expDate != null)
            {
                string ccName = g.ccName;
                string ccNo = g.ccNo;
                DateTime expDate = g.expDate;
                lblExpiryDate.Content = Convert.ToString(expDate);
                lblCardholderName.Content = ccName;
                lblCardholderNo.Content = Convert.ToString(ccNo);
                lblCheckInDate_CO.Content = b.checkInDate;

            }
        }
        private void btnSubmitPayment_Click(object sender, RoutedEventArgs e)
        {
            double minibarTotal = 0.0;
            double sprite = 2.5;
            double coke = 2.5;
            double mineralWater = 2.0;
            double sparklingWater = 3.0;
            double kitKat = 2.0;
            double potatoChip = 2.0;
            if (checkBox1.IsChecked == true)
            {
                minibarTotal = minibarTotal + sprite;
            }
            if (checkBox2.IsChecked == true)
            {
                minibarTotal = minibarTotal + coke;
            }
            if (checkBox3.IsChecked == true)
            {
                minibarTotal = minibarTotal + mineralWater;
            }
            if (checkBox4.IsChecked == true)
            {
                minibarTotal = minibarTotal + sparklingWater;
            }
            if (checkBox5.IsChecked == true)
            {
                minibarTotal = minibarTotal + kitKat;
            }
            if (checkBox6.IsChecked == true)
            {
                minibarTotal = minibarTotal + potatoChip;
            }
            {
                Booking b = new Booking();
                Room r = new Room();
                r = RoomDBManager.GetRoomByRoomNum(Convert.ToInt32(cBoxPaymentRoom.SelectedItem));
                b = CheckoutDBManager.GetBookingByroomNum(Convert.ToInt32(cBoxPaymentRoom.SelectedItem));
                int roomNum = b.roomNum;
                DateTime checkOut = Convert.ToDateTime(dPickUpdateCheckOut.Text);
                CheckoutDBManager.UpdateGuestCheckOutDate(roomNum, checkOut);
            }

            {
                Booking b = new Booking();
                Room r = new Room();
                r = RoomDBManager.GetRoomByRoomNum(Convert.ToInt32(cBoxPaymentRoom.SelectedItem));
                b = CheckoutDBManager.GetBookingByroomNum(Convert.ToInt32(cBoxPaymentRoom.SelectedItem));
                int roomNum = b.roomNum;
                int bookingId = b.bookingId;
                string roomType = r.roomType;
                DateTime checkIn = b.checkInDate;
                DateTime checkOut = b.checkOutDate;
                double roomRate = Convert.ToDouble(b.roomRates);
                TimeSpan daysStayed = checkOut - checkIn;
                int noOfDaysStayed = Convert.ToInt32(daysStayed.Days);
                int noOfNightsStayed = noOfDaysStayed - 1;
                double roomCost = roomRate * noOfDaysStayed;
                double totalCost = roomCost + minibarTotal;
                ComboBoxItem selectedItem = (ComboBoxItem)(cBoxPaymentType.SelectedValue);
                string paymentMode = (string)(selectedItem.Content);
                

                CheckoutDBManager.UpdateGuestCheckOutDate(roomNum, checkOut);
                CheckoutDBManager.UpdateGuestTotalPrice(roomNum, Convert.ToDecimal(totalCost));
                Invoice i = new Invoice();
                i.noOfDayStayed = noOfDaysStayed;
                i.noOfNightStayed = noOfNightsStayed;
                i.bookingID = bookingId;
                i.checkInDate = checkIn;
                i.checkOutDate = checkOut;
                i.roomNum = roomNum;
                i.roomRate = Convert.ToDecimal(roomRate);
                i.roomType = roomType;
                i.addCost = Convert.ToDecimal(minibarTotal);
                i.totalPrice = Convert.ToDecimal(totalCost);
                i.paymentMode = paymentMode;
                CheckoutDBManager.InsertInvoice(i);

                lblAdditionalCost.Content = "$" + Convert.ToString(minibarTotal);
                lblBookingId.Content = Convert.ToString(bookingId);
                lblRoomNum1.Content = Convert.ToString(roomNum);
                lblNoOfDaysStayed.Content = Convert.ToString(noOfDaysStayed);
                lblNoOfNightsStayed.Content = Convert.ToString(noOfNightsStayed);
                lblPaymentMode.Content = paymentMode;
                lblCheckInDate1.Content = Convert.ToString(checkIn);
                lblCheckOutDate1.Content = Convert.ToString(checkOut);
                lblRoomRate.Content = Convert.ToString(roomRate);
                lblTotalCost.Content = "$" + Convert.ToString(totalCost);
                lblRoomType1.Content = roomType;
            }
            {
                int bookingId = Convert.ToInt32(lblBookingId.Content);
                Invoice i = CheckoutDBManager.GetInvoiceIDByBookingId(bookingId);
                int invoiceId = i.invoiceID;
                lblInvoiceID.Content = Convert.ToString(invoiceId);   
            }



        }


        
        private void cBoxGuestNo_DropDownOpened(object sender, EventArgs e)
        {
            dGBookingDetails.Visibility = Visibility.Hidden;
        }

        private void tabCheckOut_loaded(object sender, RoutedEventArgs e)
        {
            ArrayList booking = new ArrayList();
            booking = BookingDBManager.GetAllGuestNo();
            foreach (Booking b in booking)
            {
                cBoxGuestNo.Items.Add(Convert.ToString(b.guestNo));
            }
        }

        
        





        

        


    }
}
